package com.bos.service.impl;
import com.bos.dao.repositories.TakeTimeRepository;
import com.bos.domian.base.TakeTime;
import com.bos.service.TakeTimeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
 * @author misterWei
 * @create 2018年11月16号:09点44分
 * @mailbox mynameisweiyan@gmail.com
 */
@Service
@Transactional
public class TakeTimeServiceImpl implements TakeTimeService{
    @Autowired
    private TakeTimeRepository takeTimeRepository;

    @Override
    public void takeTimeSaveOrUpdate(TakeTime takeTime) {
        this.takeTimeRepository.save(takeTime);
    }

    @Override
    public Map takeTimePageQuery(Integer page, Integer rows) {
        Page<TakeTime> all = takeTimeRepository.findAll(new PageRequest(page, rows));
        Map<String,Object> takeTimeList  = new HashMap<>();
        takeTimeList.put("total",all.getTotalElements());
        takeTimeList.put("rows",all.getContent());
        return takeTimeList;
    }

    @Override
    public void takeTimeDelete(String[] splitIds) {
        //删除操作
        for (String splitId : splitIds) {
            takeTimeRepository.delete(Integer.parseInt(splitId.trim()));
        }
    }

    @Override
    public List<TakeTime> findAll() {
        return takeTimeRepository.findAll();
    }
}
